/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Model.Curve;
import Control.Point;
import Control.Point;
import Control.View;
import Control.View;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *
 * @author PhucAnh
 */
public class Line extends Shape{
   Point pointStart;
   Point pointFinish;
   
   int x1,y1,x2,y2;
   
   public Line(){
   
   }
   
   public Line(Point pointStart, Point pointFinish, Color color, int basicStrok){
        super(color, basicStrok);
        this.pointStart = pointStart;
        this.pointFinish = pointFinish;
        
        x1 = pointStart.getX();
        x2 = pointFinish.getX();
        y1 = pointStart.getY();
        y2 = pointFinish.getY();        
   }
       public void setPoint2(Point pointFinish){
           this.pointFinish = pointFinish;
        
        x1 = pointStart.getX();
        x2 = pointFinish.getX();
        y1 = pointStart.getY();
        y2 = pointFinish.getY();  
       }
       public void drawShape(Graphics g2)
    {
        Graphics2D g= (Graphics2D)g2;
        g.setStroke(new BasicStroke(this.getBasicStroke()));
        g.setColor(this.getColor());
        g.drawLine(x1, y1, x2, y2);
    }
        public void drawShape(Graphics g, BufferedImage a) {
       
//        throw new UnsupportedOperationException("Not supported yet.");
 Graphics2D g2D= (Graphics2D)g;
        g2D.setStroke(new BasicStroke(this.getBasicStroke()));
        g.setColor(this.getColor());
        g.drawLine(x1, y1, x2, y2);
    }
    @Override
    public void toMove(int m,int n)
    {
        x1 +=m;
        y1 +=n;
        x2 +=m;
        y2 +=n;
    }
    
    public boolean isContain(Point p){
        if(pointFinish.getX()>=pointStart.getX() && pointFinish.getY()>=pointStart.getY()){
            if(p.getX()>= pointStart.getX() && p.getX()<= pointFinish.getX() 
            && p.getY()>= pointStart.getY() && p.getY()<= pointFinish.getY()){
                return true;
            } else {
                return false;
            }
        } else if (pointFinish.getX()<pointStart.getX() && pointFinish.getY()<pointStart.getY()){
            if(p.getX()>= pointFinish.getX() && p.getX()<= pointStart.getX() 
            && p.getY()>= pointFinish.getY() && p.getY()<= pointStart.getY()){
                return true;
            } else {
                return false;
            }
        } else if (pointFinish.getX()>=pointStart.getX() && pointFinish.getY()<=pointStart.getY()){
            if(p.getX()>= pointStart.getX() && p.getX()<= pointFinish.getX() 
            && p.getY()>= pointFinish.getY() && p.getY()<= pointStart.getY()){
                return true;
            } else {
                return false;
            }
        } else {
            if(p.getX()>= pointFinish.getX() && p.getX()<= pointStart.getX() 
            && p.getY()>= pointStart.getY() && p.getY()<= pointFinish.getY()){
                return true;
            } else {
                return false;
            }
        }
    }
        public void drawShape1(Graphics g,int time,View a){
            Graphics2D g2D=(Graphics2D)g;
            g2D.setStroke(new BasicStroke(this.getBasicStroke()));
        g.setColor(this.getColor());
        int x=pointFinish.getX()- pointStart.getX();
        int y=pointFinish.getY()- pointStart.getY();
        Point tmp=new Point();
        for(int i=0;i<time;i++){
            tmp.setX(x*i/time+pointStart.getX());
            tmp.setY(y*i/time+pointStart.getY());
            g.drawLine(pointStart.getX(), pointStart.getY(), tmp.getX(), tmp.getY());
        try {
                Thread.sleep(time);
            } catch (InterruptedException ex) {
                Logger.getLogger(Curve.class.getName()).log(Level.SEVERE, null, ex);
            }
        a.repaint();
        }
        
    }
 
}
